<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
    @include('common-css')
    <style>

        .input_box {
            width: 100%;
            height: 40px;
            margin-top: 15px;
            margin-bottom: 15px;
            display: flex;
            justify-content: flex-start;
            align-items: center;
        }

        .input_label {
            width: 120px;
            box-sizing: border-box;
        }

        .project-table {
            margin-top: 15px;
        }

        .status-tag {
            color: #1890ff;
            border: 1px solid #91d5ff;
            border-radius: 3px;
            background: #e6f7ff;
            font-size: 12px;
            padding: 2px 3px;
        }

        .ant-table-tbody > tr > td, .ant-table-thead > tr > th {
            vertical-align: middle;
            line-height: 25px;
        }

        .search_box {
            width: 1000px;
        }

        .search_box input {
            width: 300px;
        }

        .search_box button {
            margin-left: 20px;
        }

        .search_box .ant-select {
            margin-left: 20px;
        }
    </style>
</head>
<body>


<div id="app"></div>


<script id="appTemplate" type="x-template">
    <a-locale-provider :locale="antdLocale">
        <div class="container">

            @include('admin.header-tpl')

            <main>
                <div class="common_container">

                    @include('admin.aside-tpl')

                    <div class="common_content admin_common_content">
                        <p style="margin-top: 20px; margin-bottom: 20px; font-weight: bold">@{{ awardedProjectStatsInfo }}</p>
                        <a-table class="project-table"
                                 rowKey="id"
                                 size="small"
                                 :columns="projectTableColumns"
                                 :dataSource="filteredProjects"
                                 :loading="loadingPageData"
                                 :pagination="{pageSize: 10000, hideOnSinglePage: true, position: 'both', showTotal: total => `共 ${total} 项`}">
                            <span slot="applicant" slot-scope="text, record">
                                申报者：@{{ record.applicant_name }}<br>
                                电话：@{{ record.applicant_tel }}<br>
                                单位：@{{ record.applicant_work_org_name }}
                            </span>
                            <span slot="application_form" size="large" slot-scope="text, record">
                                <a :href="'/home/view-form?id=' + record.id" target="_blank">查看</a>
                            </span>
                            <span slot="attachments" slot-scope="text, record">
                                <a :href="'/home/view-attachments?project_id=' + record.id" target="_blank">
                                    <span>查看</span>
                                </a>
                            </span>
                        </a-table>
                    </div>

                </div>
            </main>

        </div>
    </a-locale-provider>
</script>

@include('common-js')
@include('admin.header-js')
@include('admin.aside-js')

<script>
    var queryParams = parseUrl(location.href).params;
    var awardsInfo = {!! json_encode(array_values(config('vars.awards')), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) !!};

    var projectTableColumns = [
        {
            width: 60,
            title: '序号',
            dataIndex: 'num'
        },
        {
            width: 150,
            title: '项目名称',
            dataIndex: 'project_name',
        },
        {
            width: 150,
            title: '申报者',
            key: 'applicant',
            scopedSlots: {
                customRender: 'applicant'
            }
        },
        {
            width: 70,
            title: '申报书',
            dataIndex: 'application_form',
            scopedSlots: {
                customRender: 'application_form'
            }
        },
        {
            width: 70,
            title: '附件',
            dataIndex: 'attachments',
            scopedSlots: {
                customRender: 'attachments'
            }
        },
        {
            width: 60,
            title: '平均分',
            dataIndex: 'avg_score',
        },
        {
            width: 70,
            title: '获奖结果',
            dataIndex: 'final_award_level',
        }
    ];
</script>

<script>
    var app = new Vue({
        el: '#app',
        template: '#appTemplate',
        data: {
            profCategoryFilter: '',
            searchKeyword: '',

            projectTableColumns,
            pageData: [],
            loadingPageData: false,

            stats: {total_count: 0, per_award: []},

            queryParams,
            awardsInfo,
            profCategories,

            asideSelectedKeys: queryParams.aside_key ? [queryParams.aside_key] : [],
            antdLocale: antd.locales.zh_CN,
            ...AdminHeader.data,
            ...AdminAside.data,
        },
        beforeMount() {
            this.loadAsideDefaultOpenKeys()
        },
        computed: {
            filteredProjects() {
                var projects = this.searchFilteredProjects;
                if (this.profCategoryFilter) {
                    projects = projects.filter(project => {
                        return project.prof_category == this.profCategoryFilter
                    })
                }
                var num = 1;
                projects.forEach(project => {
                    project.num = num++
                });
                return projects
            },
            searchFilteredProjects() {
                var projects;
                if (this.searchKeyword) {
                    var q = this.searchKeyword.trim();
                    projects = this.pageData.filter(project => {
                        var text = project.project_name + project.applicant_name + project.applicant_org_name + project.applicant_tel + project.applicant_email;
                        return text.toLowerCase().indexOf(q) != -1
                    })
                } else {
                    projects = this.pageData
                }
                return projects
            },
            awardedProjectStatsInfo() {
                let info = '';
                for (let item of this.stats.per_award) {
                    info += `${item.award} ${item.count} 个，`
                }
                info += `共 ${this.stats.total_count} 个奖项。`
                return info
            }
        },
        mounted() {
            this.reloadPageData();
        },
        methods: {
            reloadPageData() {
                this.loadingPageData = true;
                axios.get('/api/award/get-awarded-projects', {
                    params: {large_group_id: this.queryParams.large_group_id }
                }).then(response => {
                    if (response.data.ok) {
                        this.stats = response.data.stats
                        this.pageData = response.data.projects;
                    } else {
                        error('加载页面数据失败: ' + response.data.msg)
                    }
                    this.loadingPageData = false
                })
            },
            ...AdminHeader.methods,
            ...AdminAside.methods,
        }
    })
</script>

</body>
</html>